package com.zygh.interactiveplatform.module.controller;


import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.Operation;
import com.zygh.interactiveplatform.module.entity.vo.OperationVo;
import com.zygh.interactiveplatform.module.service.LogTrendService;
import com.zygh.interactiveplatform.module.service.OperationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lee
 * @since 2021-01-29
 */
@RestController
@RequestMapping("/operation")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_OPERATION})
public class OperationController {
    @Resource
    private OperationService operationService;
    @Resource
    private LogTrendService logTrendService;

    @ApiOperation(value = "日志管理新增", notes = "日志管理新增")
    @PostMapping("addOperatione")
    @PcLog(logType = "2", module = SwaggerTagConst.Admin.MANAGER_OPERATION, content = "日志管理新增")
    public ResponseDTO addOperatione(@RequestBody @Valid Operation operation) {
        return operationService.addOperation(operation);
    }

    @ApiOperation(value = "日志管理修改", notes = "日志管理修改")
    @PostMapping("updateOperation")
    @PcLog(logType = "3", module = SwaggerTagConst.Admin.MANAGER_OPERATION, content = "日志管理修改")
    public ResponseDTO updateOperation(@RequestBody @Valid Operation operation) {
        return operationService.updateOperation(operation);
    }

    @ApiOperation(value = "日志管理删除", notes = "日志管理删除")
    @PostMapping("deleteOperation")
    @PcLog(logType = "4", module = SwaggerTagConst.Admin.MANAGER_OPERATION, content = "日志管理删除")
    public ResponseDTO deleteOperation(@RequestBody String id) {
        String s = JSONObject.parseObject(id).get("id").toString();
        Integer new_id = Integer.parseInt(s);
        return operationService.deleteOperation(new_id);
    }

    @ApiOperation(value = "根据条件查询日志管理", notes = "根据条件查询日志管理")
    @PostMapping("findOperationLog")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_OPERATION, content = "根据条件查询")
    public ResponseDTO findOperationLog(@RequestBody OperationVo operation) {
        return operationService.findOperationLog(operation);
    }
    @ApiOperation(value = "事件分类", notes = "事件分类")
    @GetMapping("eventStatistics")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_OPERATION, content = "事件分类")
    public ResponseDTO eventStatistics() {
        return operationService.eventStatistics();
    }

    @ApiOperation(value = "事件采集趋势", notes = "事件采集趋势")
    @GetMapping("findLogTrendAllDay")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "事件采集趋势")
    public Object findLogTrendAllDay() {
        return logTrendService.findLogTrendAllDay();
    }

    @ApiOperation(value = "事件等级", notes = "事件等级")
    @GetMapping("eventLevel")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "事件等级")
    public Object eventLevel() {
        return operationService.eventLevel();
    }

}
